/* 
 * File:	main.c
 * Authors: Johan Dahlberg <S102591>
 *				Daniel Jansson <S102496>
 * ---------------------------------
 * Task 1: Pyramid
 */
#include "graphics.h"

#define TRIANGEL_SIZE 0.005
#define ROWS 1000

void printPyramidRow(int nRows, int nCols);
void printTriangleEven(int nCols);
void printTriangleOdd(int nCols);

main() {
	InitGraphics();
	if(ROWS == 1) {
		printPyramidRow(1, 1, 1);
	} else {
		printPyramidRow(ROWS, ROWS, (ROWS * 2) - 1);
	}
}

void printPyramidRow(int startRows, int nRows, int nCols) {
	if(nRows == 0) {
		return;
	} else {
		/*if(startRows == nRows) { // prevent division by zero error
			MovePen(0.5 * TRIANGEL_SIZE, 1 * TRIANGEL_SIZE);
		} else {*/
		MovePen(0.5 + ((startRows - nRows) * 0.5) * TRIANGEL_SIZE, ((startRows - nRows) + 1) * TRIANGEL_SIZE);
		
		printTriangleOdd(nCols);
		printPyramidRow(startRows, nRows - 1, nCols - 2);
	}
}

void printTriangleEven(int nCols) {
	if(nCols == 0) {
		return;
	} else {
		DrawLine(1 * TRIANGEL_SIZE, 0);

		printTriangleOdd(nCols - 1);
	}
}

void printTriangleOdd(int nCols) {
	if(nCols == 0) {
		return;
	} else {
		DrawLine(-0.5 * TRIANGEL_SIZE, -1 * TRIANGEL_SIZE);
		DrawLine(1 * TRIANGEL_SIZE, 0);
		DrawLine(-0.5 * TRIANGEL_SIZE, 1 * TRIANGEL_SIZE);

		printTriangleEven(nCols - 1);
	}
}